<%@ page language="java" import="java.util.*,com.wcll.www.ShowSortBean" pageEncoding="UTF-8" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'managerpage.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  <jsp:useBean id="pages" class="com.wcll.www.ShowSortBean"></jsp:useBean>
  <jsp:setProperty name="pages" property="*"/>
  <body style="margin:0px;">
    <%
    request.setCharacterEncoding("UTF-8");
    if(request.getAttribute("hm")!=null){
    	ArrayList<ShowSortBean> hm = (ArrayList<ShowSortBean>)request.getAttribute("hm");
    	Iterator<ShowSortBean> ihm =hm.iterator();
    	%>
    			  		     <span style="font-size:12px;">
    <% 
    request.setCharacterEncoding("UTF-8");
    if(request.getParameter("msg")!=null){
    	String s = request.getParameter("msg");
    	if(s.equals(new String("succeed"))){
    	%>
    	成功
    	<%}%>
    	<%
    	if(s.equals(new String("failed"))){
    	%>
    	失败，请重试
    	<%} %>
    <%}%>
    </span>
    	<table width="100%" style="text-align:center;font-size:12px;" border="1">
    		<tr>
    			<td>编号</td>
    			<td>种别</td>
    			<td colspan="3" align="center">其本操作</td>
    		</tr>
    		
    		<% 
    	while(ihm.hasNext()){
    		ShowSortBean aa = ihm.next();
    		%>
    		<tr>
    		<td><%=aa.getId() %></td>
    		<td><%=aa.getName()%></td>
    		<td><span style="text-decoration:underline;cursor:hand;" onClick="xiugai(<%=aa.getId() %>,'<%=aa.getName()%>');">修改</span>&nbsp;|&nbsp;<span style="text-decoration:underline;cursor:hand;" onClick="dele(<%=aa.getId() %>);">删除</span></td>
    		<td><span style="text-decoration:underline;cursor:hand;" onclick="chakan(<%=aa.getId() %>);">察看子类</span></td>
    		<td><span style="text-decoration:underline;cursor:hand;" onClick="zjzl(<%=aa.getId() %>,'<%=aa.getName()%>');">增加一个子类</span></td>
    		</tr>
    	<%}} %>
    	
    	</table>
    <div id = "dd" style="display:none;position:absolute;top:200px;left:200px;z-index:10;width:350px;">
	<span style="float:right;cursor:hand;font-size:12px;" onClick="hidden();">[&nbsp;关闭&nbsp;]</span>
	<span id="js"></span>
	<form id="ff" action="" method="POST">
	<input type="hidden" id="jsid" name="jsid" />
	<table style="text-align:center;font-size:12px;" border="1">
	<tr>
	<td>名称:</td>
	<td><input type="text" id="jsname" name="jsname" /></td>
	</tr>
	<tr>
	<td colspan="2" align="center"><input type="submit" value="确认" onClick="hidden();"/></td>
	</tr>
	</table>
	</form>
</div>
<span style="font-size:12px;float:left;">
<%
	int p = pages.getCounts("select count(*) as a from job_assort");
	for(int i =1;i<=p;i++){
	%>
	<a href="<%=basePath%>servlet/ShowSortServlet?currage=<%=i %>">第<%=i %>页</a>
	<%}
 %>
</span>
<div style="font-size:12px;float:right;">请输入类别:<input type="text" name="jsort" id="jsort" /><input type="button" value="增加" onClick="zengjia();"/><span id="sp1" style="display:none;float:right;"><a href="<%=basePath %>/servlet/ShowSortServlet">察看</a></span><span id="sp" style="display:none;float:right;"/></span></div>
  </body>
</html>
<script src="./includes/ajax.js"></script>
<script>
function xiugai(id,mingcheng){
	var d = document.getElementById("dd");
	var ff = document.getElementById("ff");
	var jsid = document.getElementById("jsid");
	var jsname = document.getElementById("jsname");
	ff.action = "<%=basePath%>/servlet/ModifyServlet";
	jsid.value = id;
	jsname.value = mingcheng;
	d.style.display="block";
}
function hidden(){
	var d = document.getElementById("dd");
	d.style.display="none";
}
function dele(id){
	location="<%=basePath%>/servlet/DeleteJSAvatarServlet?deleid="+id;
}
function zjzl(id,mingcheng){
	var d = document.getElementById("dd");
	var ff = document.getElementById("ff");
	var js = document.getElementById("js");
	var jsa = document.getElementById("jsid");
	var jsname = document.getElementById("jsname");
	ff.action="<%=basePath%>/servlet/IncreaseJSAvatarServlet";
	js.innerHTML = mingcheng;
	jsa.value = id;
	jsname.value = "";
	d.style.display="block";
}
function chakan(id){
   location = "<%=basePath%>/servlet/JobSortServlet?id="+id;
}
function zengjia(){
	var jsort = document.getElementById("jsort").value;alert(jsort);
	var ajax = initAjax();
	var url = encodeURI("<%=basePath%>/servlet/IncreaseJobSortServlet?jsort="+jsort+"&r="+Math.random());
	ajax.open("get",url,true);
	ajax.send(null);
	ajax.onreadystatechange = function (){
		if(ajax.readyState == 4){alert(ajax.responseText);
		var sp = document.getElementById("sp");
		var sp1 = document.getElementById("sp1");
		sp.innerHTML = ajax.responseText;
		sp.style.display="block";
		sp1.style.display="block";
		}
	}
}
</script>